<?php
require_once 'Hamlap/Haml.php';
/**
 * View class for use in Zend Framework projects.
 *
 * @link http://haml-lang.com/ Original Haml parser (for Ruby)
 * @license http://www.opensource.org/licenses/mit-license.php MIT (X11) License
 * @author Rik Bruil <info@rikbruil.com>
 * @package Hamlap
 */
class Hamlap_View extends Zend_View_Abstract
{
	/**
	 * Contains the Hamlap_Haml object
	 * @var Hamlap_Haml
	 */
	protected $_haml;

	/**
	 * Instantiate the view object and set the
	 * Hamlap_Haml object with passed options
	 * @param array $options
	 */
	public function __construct(array $options = array())
	{
		$this->_haml = new Hamlap_Haml($options);
	}

	protected function _run()
	{
		return $this->_render(func_get_arg(0));
	}

	/**
	 * Render the template contents
	 * @param string $name
	 */
	public function _render($name)
	{
		$this->_haml->parse($name);
		if($content = $this->_haml->render())
			($this->_haml->getOption('compile') && is_file($content)) ? include $content : eval('?>'.$content);
	}
}